﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CCWin;
using CCWin.Win32;
using CCWin.Win32.Const;
using CCWin.SkinControl;
using GroupChat2013.Common;
using GroupChat2013.Entity;
using GroupChat2013.Logic;

namespace GroupChat2013.Main
{
    public partial class FrmMessage : CCSkinMain
    {
        private InformationItem informationItem;

        private Color outColor = SystemColors.InfoText;
        private Color inColor = SystemColors.HotTrack;

        public FrmMessage(string title, string content, string url)
        {
            InitializeComponent();
            this.Text = title;

            informationItem = new InformationItem();
            informationItem.Content = content;
            informationItem.Url = url;

            slContent.Click += new EventHandler(slContent_Click);

            slContent.MouseEnter += new EventHandler(slContent_MouseEnter);
            slContent.MouseLeave += new EventHandler(slContent_MouseLeave);
        }

        //窗口加载时
        private void FrmInformation_Load(object sender, EventArgs e)
        {
            SetView();
        }

        private void slContent_MouseLeave(object sender, EventArgs e)
        {
            var item = slContent.Tag as InformationItem;
            if (item != null && !string.IsNullOrEmpty(item.Url))
            {
                slContent.ForeColor = outColor;
            }
        }

        private void slContent_MouseEnter(object sender, EventArgs e)
        {
            var item = slContent.Tag as InformationItem;
            if (item != null && !string.IsNullOrEmpty(item.Url))
            {
                slContent.ForeColor = inColor;
            }
        }

        private void slContent_Click(object sender, EventArgs e)
        {
            var item = slContent.Tag as InformationItem;
            if (item != null && !string.IsNullOrEmpty(item.Url))
            {
                if (FrmGroup.OpenWithChrome(item.Url))
                    this.Close();
            }
        }

        private void SetView()
        {
            slContent.Text = informationItem.Content;
            slContent.Tag = informationItem;

            if (!string.IsNullOrEmpty(informationItem.Url))
            {
                slContent.Cursor = System.Windows.Forms.Cursors.Hand;
                this.slContent.ForeColor = outColor;
            }
            else
            {
                slContent.Cursor = System.Windows.Forms.Cursors.Default;
                this.slContent.ForeColor = System.Drawing.SystemColors.InfoText;
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
